package com.kejiguan.ui.dialog;

import android.content.Context;
import android.text.SpannableString;
import android.view.View;

import com.kejiguan.ui.R;

/**
 * Created by YYY on 2016/7/15.
 */
public class CommDialogUtil {

    private static CommDialogUtil instance;
    private CommonDialog commonDialog;
    private CommonOneDialog commonOneDialog;

    public CommDialogUtil() {
    }

    public static CommDialogUtil getInstance() {
        if (instance == null) {
            synchronized (CommDialogUtil.class) {
                if (instance == null) {
                    instance = new CommDialogUtil();
                }
            }
        }
        return instance;
    }

    public void show(Context context, String message,View.OnClickListener onClickListener,String left,String right,int tag)
    {
        show(context,message,onClickListener,left,right,true,true,tag);
    }

    public void show(Context context, SpannableString message,View.OnClickListener onClickListener,String left,String right,int tag)
    {
        show(context,message,onClickListener,left,right,true,true,tag);
    }

    public void show(Context context, String message,View.OnClickListener onClickListener,String left,String right,boolean leftClickable,boolean rightClickable,int tag)
    {
        if (null == commonDialog || !commonDialog.isShowing())
        {
            commonDialog = new CommonDialog(context, R.style.dialog_tran);
        }
        commonDialog.withMessage(message);
        commonDialog.withOnClick(onClickListener);
        commonDialog.withTag(tag);
        commonDialog.withBtnTxt(left,right);
        commonDialog.leftRightClickable(leftClickable,rightClickable);
        commonDialog.show();
        commonDialog.setCanceledOnTouchOutside(true);
    }

    public void show(Context context, SpannableString message, View.OnClickListener onClickListener, String left, String right, boolean leftClickable, boolean rightClickable, int tag)
    {
        if (null == commonDialog || !commonDialog.isShowing())
        {
            commonDialog = new CommonDialog(context, R.style.dialog_tran);
        }
        commonDialog.withMessage(message);
        commonDialog.withOnClick(onClickListener);
        commonDialog.withTag(tag);
        commonDialog.withBtnTxt(left,right);
        commonDialog.leftRightClickable(leftClickable,rightClickable);
        commonDialog.show();
        commonDialog.setCanceledOnTouchOutside(true);
    }


    public void showOne(Context context, String message,View.OnClickListener onClickListener,String btnTxt,int tag)
    {
        if (null == commonOneDialog || !commonOneDialog.isShowing())
        {
            commonOneDialog = new CommonOneDialog(context, R.style.dialog_tran);
        }
        commonOneDialog.withMessage(message);
        commonOneDialog.withOnClick(onClickListener);
        commonOneDialog.withTag(tag);
        commonOneDialog.withBtnTxt(btnTxt);
        commonOneDialog.show();
        commonOneDialog.setCanceledOnTouchOutside(true);
    }


    public void dismissOne() {
        if (null != commonOneDialog && commonOneDialog.isShowing()) {
            commonOneDialog.dismiss();
        }
    }


    public void dismiss() {
        if (null != commonDialog && commonDialog.isShowing()) {
            commonDialog.dismiss();
        }

    }
}
